package com.wolfking;

import com.wolfking.aggregate.EnableConcurrentAggregate;
import com.wolfking.converter.spring.ConverterScan;
import com.wolfking.jeesite.config.SsoConfig;
import com.wolfking.spi.SpiScan;
import lombok.SneakyThrows;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *
 * @author 赵伟伟(wolfking)
 * created on 2019-09-27 11:07
 */
@Controller
@EnableSwagger2
@SpiScan("com.wolfking")
@ConverterScan("com.wolfking")
@ServletComponentScan("com.wolfking")
@EnableConcurrentAggregate("com.wolfking")
@SpringBootApplication(scanBasePackages = "com.wolfking", exclude = DataSourceAutoConfiguration.class)
public class Driver extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Driver.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(Driver.class, args);
    }

    @SneakyThrows
    @RequestMapping(value = {"/swagger*", "/doc","/docs"})
    public void doc(HttpServletResponse response) {
        response.sendRedirect("/doc.html");
    }

    @Autowired
    private SsoConfig ssoConfig;

    @SneakyThrows
    @RequestMapping(value = {"/"})
    public void index(HttpServletResponse response) {
        response.sendRedirect(ssoConfig.getSelfRootUrlByRequest() + "/login");
    }

}
